import React, { Component } from 'react';
import "../styles/myshouc.css";
import { good_favlist,good_unfav } from "../api/index";
class MyShouc extends Component {
    constructor() {
        super()
        this.state = {
            favlist: []
        }
    }
    componentDidMount() {
        good_favlist({ userid: localStorage.getItem("id") }).then((res) => {
            console.log(res.data);
            this.setState({
                favlist: res.data.list
            })
        })
    }
    dellistfav(id){
        good_unfav({userid:localStorage.getItem('id'),goodid:id}).then((res)=>{
            console.log(res.data);
            good_favlist({userid:localStorage.getItem("userid")}).then((res)=>{
                console.log(res)
                this.setState({
                    favlist:res.data.list
                })
            })
        })
    }
    render() {
        return (
            <div className='shouc'>
                <h3>我的收藏</h3>
                <div >

                    {
                        this.state.favlist.map((item, index) => {
                            return (
                                <li key={index}>
                                    <img src={item.pic} alt="" />
                                    <div className='word'>
                                        <p> {item.name}</p>
                                        <div className='bujingq'>
                                            <h4>${item.salesPrice.value}</h4></div>
                                    </div>
                                    <button onClick={()=>{this.dellistfav(item.id)}} >取消收藏</button>
                                </li>
                            )
                        })
                    }

                </div>
            </div>
        );
    }
}

export default MyShouc;